Definition of regular languages using fsm - regular-language

I went across the definition of regular languages and i found this property:
A language is said to be regular if and only if some FSM recognizes it
and as an example :
{a^n, b^m} isn't a regular language..
However I think this can be represented using the following DFA :
https://i.imgur.com/FXh6BPo.png
Any explanation on where I'm wrong is so welcomed.
Thank you.

Related

Given an antlr4 grammar, can I build up an expression tree?

So I have written my grammar in antlr4 syntax. Then I setup codegeneration, and now I can parse source files in my own defined language. This works great!
The next step I took is to create an object model from the expression tree. This is also working well.
However, now I want to generate an expression from my object model.
Can I generate code using the generated language parser objects API? Obviously, I can write methods that hand-generates strings. But I want to use a geenrated API based on the grammar to achieve some level of type safety and to detect errors when I make a grammar change.
I'm using the latest antlr4: antlr 4.7.1.
There's no generated solution. You have to wire this all up manually.

What name does this syntax have

In the language nim, one can do the following thing:
let num = 5.add(3)
which would be the same as
let num = add(5,3)
So, basically you take the expression before the dot as the first argument to the function.
I'm sure other languages have this feature, but none directly came to mind.
What I want to know is what name this syntax has
In D lang this syntax is called Uniform Function Call Syntax (UFCS).
The manual says it's the method call syntax. It also mentions dot operators.
TL;DR - Unified [Function] Call Syntax, or whatever you like, because there's no stable widely accepted term for that in software engineering.
The concern is based on the info about programming languages that somehow implement this feature:
C++: The most generic name for the feature is possibly Unified Call Syntax as defined by Herb Sutter at open-std.org paper in cooperation with Bjarne Stroustrup as a possible new feature for further C++ standards.
D2: In D language, and also in and RFC for the Rust Language it is called UFCS (Unified Function Call Syntax).
MATLAB: In MATLAB they don't use any specific naming for the fact methods can be called either via function notation or via '.' (dot) syntax.

OCUP UML operation semantics example

I am currently learning for the OCUP UML Fundamental exam.
While reading the book i found something strange about operations.
The semantics of an operation:
[visibility] name (parameter list)[:type][{property strings}]
now there are the following examples:
- getPoistion(return x: int, return y: int)
- enlarge(byFactor: Real) : GeomFigure
- +addPhone(phone:String)
- deposit(in amount, Amount): Amount
- #release(): contractStatus
- "create"create()
The last one i think is odd. Can someone explain me why this is allowed?
Since the only semantics that is allowed before the name is a visibility modifier.
Kind regards,
Wim
The chapter 2.2.11 OPERATIONS, page 49, in the book http://issuu.com/maurosergio/docs/uml_2_certification_guide_-_fundamental_and_interm that you are quoting also says
..Notation and Semantics..The syntax for operations..the notation should look like this..
The notation does not define/restrict semantic meaning of operations. It specifies general useful syntax.
The "create" message has in UML special behavioral meaning (don't know where is it explained in the book you are reading). For example look here http://www.uml-diagrams.org/sequence-diagrams.html, see <<create>> stereotype in the diagram and create message later in the text.
Also see "Object Creation Message" chapter here http://www.uml-diagrams.org/uml-object-oriented-concepts.html#message
Kirill Fakhroutdinov's online book www.uml-diagrams.org is very good UML reference compiled by the author from official sources (UML specs) and also from other background non-UML sources and from some "common sense".
Browsing through this book might be easier way to prepare for the exam, or at least consider it as alternative reading. Many "visual" examples included
and welcome to Stack Overflow and also read https://stackoverflow.com/help/someone-answers
Where exactly have you found this example? It really looks like incorrect and definitely does not comply to the formal expression stated above.
These are the examples frm the last version of UML spec and all are perfectly fine:
9.6.5 Examples Normal Operations:
display ()
-hide ()
+createWindow (location: Coordinates, container: Container [0..1]): Window
+toString (): String
A template Operation: f <T:Class>(x : T)
A binding of that template Operation. f << T -> Window >>(x : Window)
NOTE. Parameters may be suppressed; .
If you have taken the example from an informal source, it is clearly an error. I would forget about it. :)

What the semantic NULL <Real>() in C++ mean

I have a problem of understanding the semantic Null<Real>() in C++, is it a function object?
Thanks,
Eric
Neither Null nor Real have any meaning provided by the C++ standard.
They're legal identifiers for use in your code. And their meaning is defined by your code.
The snippet you provided certainly looks like a call to a template function, or default construction of a template type. But it's hard to day without seeing the definitions.

How to find matching expressions while using a ParseTreeWalker

Say I'd like to find instances of the expression while using the Java7 grammar:
FoobarClass.getInstanceOfType("Bazz");
Using a ParseTreeWalker and listening to exitExpression() calls sounded like a good first place to start. What surprised me was the level of manual traversal of the Java7Parser.ExpressionContext required to find expressions of this type.
What's the appropriate method to find matches to the above expression? At this point using a Regex in place of ANTLR4 yields simpler code, but this won't scale.
ANTLR 4 does not currently include feature allowing you to write concrete or abstract syntax queries. We hope to add something in the future to help with this type of application.
I've needed to write a few pattern recognition features for ANTLR 4 parse trees. I implemented the predicate itself with relative success by extending BaseMyParserVisitor<Boolean> (the parser in this example is called MyParser).

Resources