Serge D. Mechveliani wrote:
>
> I need to program a certain specialized parser (: String -> ...),
> as
> the category + its instances for the constructors of
> Integer, Vector, Fraction, Poly, and such.
>
> So far, I doubt, probably, it is needed to first break to lexemes:
> "(2*powerProduct([4,1,2])+1*Product([])" -->
>
> [ "(", "2", "*", "powerProduct", "(", "[", "4", ",", ... ],
>
> and then, to do the real parsing for lexemes. This will mostly need to
> operate with generic lists.
> By the way, what are lexemes in the Spad language?
> Has the library a function that breaks a string to the Spad lexemes?
> In DoCon, I use the Haskell lexemes for this and the corresponding library
> function for breaking to lexemes (and this also defines what is a lexeme).
You may with to look at Lisp function READ-FROM-STRING. One can
use it to convert string into arbitrary Lisp data. In particular
(1) -> READ_-FROM_-STRING("(|powerProduct| 4 1 2)")$Lisp
(1) (powerProduct 4 1 2)
Type: SExpression
that is you may easily get list of whatever entries you need.
The return type of calls to Lisp function is SExpression,
but one can convert it to apropriate type.
FriCAS has two parsers and two lexers. One lexer+parser is
used by interpreter, the other one the Spad compiler. They
use sligtly different set of lexems, for example in
interpreter 'break' is a keyword, while in Spad compiler
it is an identifier (with magic meaning to compiler).
You may ask what is difference between keyword and an
identifier with magic meaning -- well, keyword is marked
as keyword by the lexer, magic identifier is handled
as all other identifiers by the lexer and only later
recognized by compiler. I plan to remove lexer which
is currently used by Spad compiler, so better do not
use it.
The lexer used by interpreter is written in Boot and
uses lisp data structures. Each token (lexem) is represented
as a list, first element ot this list gives you kind
of the token (identifier, keyword, string, character,
integer, float) the second the actual token, keywords
and identifers as Lisp symbols, the other as strings.
There is also data to track locations in the input
file (needed for pile handling).
--
Waldek Hebisch
[email protected]
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fricas-devel?hl=en.