• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to determine the value type in compiler when evaluate the syntax tree?

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,every one
I post this topic in "Java in General (advanced)" also,but no result,so I post it here,
I'm writing a interpreter of a expression language by javacc,javacc works well ,it parses it ,and genrate a right syntax tree.but when I evaluate this tree,a problem appeared:
I was forced not to distinguish the different form of the value types of the identifiers in expression,and there is no type define statements,just one expression, but there is two types of value,the numric and the string(string type is only used as function argumnet),for example: in expression "a*b","a" should be numeric,but in "sum(a)" ,"a" should be string,in tree node ,they all are identifiers,how can I resolve this?
The EBNF of the language is following(just focus on the production 9-12,identifiers act as function name at the same time):
1.)formalu->logicExpression
2.)logicExpression->AndExpression {|| AndExpression}
3.)AndExpression->EqualityExpression {&& EqualityExpression}
4.)EqualityExpression->RelationalExpression {(==|!=) RelationalExpression}
5.)RelationalExpression->AdditiveExpression {(>|<|>=|<=) AdditiveExpression}
6.)AdditiveExpression->MultiplicativeExpression {(+|-) MultiplicativeExpression}
7.)MultiplicativeExpression->UnaryExpression {(*|/|%) UnaryExpression}
8.)UnaryExpression->[(+|-)]literal
9.)literal-><INTEGER_LITERAL>|<FLOATING_POINT_LITERAL>|<COLUMNNAME>|<IDENTIFIER> [arguments]|(formalu)
10.)arguments->([argumentList])
11.)argumentList->argument {,argument}
12.)argument->{argumentList}|formula
 
Water proof donuts! Eat them while reading this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic