"hello world" parser for lemon

928 views Asked by At

I try my best for hours now to create a y-file for the lemon parser (respectivly PEAR's PHP_LexerGenerator) that parses a simple "hello + world".

I used this (German) tutorial and yes it's nice to have a calculator tutorial, but at the end, I want to parse some more complex stuff (with "variables").

What would be the definition for this "language" parsing/tokenizing "hello + world"?

This is among many other things what I tried:

/* %name, %declare_class, %token_prefix, %syntax_error, .. removed */

%left S.
%left PLUS MINUS.

%right IDENT.

start(res)       ::= expression(expr). { res = expr; }

/* The common stuff */
expression(res)  ::= expression(e1) PLUS expression(t2). { res = e1+t2; }
expression(res)  ::= expression(e1) MINUS expression(t2). { res = e1-t2; }
expression(res)  ::= NUMBER(n). { res = n; }
expression(res)  ::= IDENT(n). { res = (n * 0) + 99; }

Instead of IDENT, I also tried VALUE, string, ... Not even the SQLite/parser.y file did help me.

Thanks for your help.

0

There are 0 answers