Goldie Parsing System v0.4 Released - Now for D2
Nick Sabalausky
a at a.a
Sat Apr 16 15:47:52 PDT 2011
"Kagamin" <spam at here.lot> wrote in message
news:iod552$rbe$1 at digitalmars.com...
> Nick Sabalausky Wrote:
>
>> Yea, turns out that grammar just doesn't support using user-defined types
>> without preceding them with "struct", "union", or "enum". You can see
>> that
>> here:
>>
>> <Var Decl> ::= <Mod> <Type> <Var> <Var List> ';'
>> | <Type> <Var> <Var List> ';'
>> | <Mod> <Var> <Var List> ';'
>>
>> <Mod> ::= extern
>> | static
>> | register
>> | auto
>> | volatile
>> | const
>>
>> <Type> ::= <Base> <Pointers>
>>
>> <Base> ::= <Sign> <Scalar> ! Ie, the built-ins like char, signed
>> int,
>> etc...
>> | struct Id
>> | struct '{' <Struct Def> '}'
>> | union Id
>> | union '{' <Struct Def> '}'
>> | enum Id
>>
>> So when you use "MyType" instead of "struct MyType": It sees "MyType",
>> assumes it's a variable since it doesn't match any of the <Type> forms
>> above, and then barfs on "var" because "variable1 variable2" isn't valid
>> C
>> code. Normally, you'd just add another form to <Base> (Ie, add a line
>> after
>> " | enum Id" that says " | Id "). Except, the problem is...
>>
>> C is notorious for types and variables being ambiguous with each other.
>
> As I understand, <Type> is a type, <Var> is a variable. There should be no
> problem here.
First of all, the name <Var> up there is misleading. That only refers the
the "name of the variable" in the variable's declaration. When actually
*using* a variable, that's a <Value>, which is defined like this:
<Value> ::= OctLiteral
| HexLiteral
| DecLiteral
| StringLiteral
| CharLiteral
| FloatLiteral
| Id '(' <Expr> ')' ! Function call
| Id '(' ')' ! Function call
| Id ! Use a variable
| '(' <Expr> ')'
So we have a situation like this:
<Type> ::= <Base>
<Base> ::= Id
<Value> ::= Id
So when the parser encounters an Id, how does it know whether to reduce it
to a <Base> or a <Value>? Since they can both appear in the same place (Ex:
Immediately after a left curly-brace, such as at the start of a function
body), there's no way to tell.
Worse, suppose it comes across this:
x*y
If x is a variable, then that's a multiplication. If x is a type then it's a
pointer declaration. Is it supposed to be multiplication or a declaration?
Could be either. They're both permitted in the same place.
More information about the Digitalmars-d-announce
mailing list